home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / rxdoscmd.zip / RXDOSPRM.ASM < prev    next >
Assembly Source File  |  1993-06-06  |  29KB  |  780 lines

  1.         TITLE   'Prm - RxDOS Command Shell Prompt, Date, and Time'
  2.         PAGE 59, 132
  3.         .LALL
  4.  
  5.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  6.         ;  RxDOS Command Shell Prompt, Date, and Time                   ;
  7.         ;...............................................................;
  8.  
  9.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  10.         ;  Real Time Dos                                                ;
  11.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  12.         ;                                                               ;
  13.         ;  This material  was created as a published version  of a DOS  ;
  14.         ;  equivalent product.   This program  logically  functions in  ;
  15.         ;  the same way as  MSDOS functions and it  is  internal  data  ;
  16.         ;  structure compliant with MSDOS 5.0                           ;
  17.         ;                                                               ;
  18.         ;  This product is distributed  AS IS and contains no warranty  ;
  19.         ;  whatsoever,   including  warranty  of   merchantability  or  ;
  20.         ;  fitness for a particular purpose.                            ;
  21.         ;                                                               ;
  22.         ;                                                               ;
  23.         ;  (c) Copyright 1990, 1992. Api Software and Mike Podanoffsky  ;
  24.         ;      All Rights Reserved Worldwide.                           ;
  25.         ;                                                               ;
  26.         ;  This product is protected under copyright laws and  may not  ;
  27.         ;  be reproduced  in whole  or in part, in any form  or media,  ;
  28.         ;  included but not limited to source listing, facimilie, data  ;
  29.         ;  transmission, cd-rom, or  floppy disk without the expressed  ;
  30.         ;  written consent of the author.                               ;
  31.         ;                                                               ;
  32.         ;  Licence for distribution in commercial use:                  ;
  33.         ;                                                               ;
  34.         ;  Api Software                                                 ;
  35.         ;  12 South Walker Street                                       ;
  36.         ;  Lowell,  MA   01851                                          ;
  37.         ;  508/ 454-4961.                                               ;
  38.         ;                                                               ;
  39.         ;...............................................................;
  40.  
  41.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  42.         ;  RxDOS Command Shell                                          ;
  43.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  44.         ;                                                               ;
  45.         ;  Programmer's Notes:                                          ;
  46.         ;                                                               ;
  47.         ;  Command Shell consists of  two parts bound  together into a  ;
  48.         ;  single executable load.  There  exists  a  single  resident  ;
  49.         ;  command shell which is accessible by an Int 2Eh.             ;
  50.         ;                                                               ;
  51.         ;...............................................................;
  52.  
  53.         include rxdosmac.asm
  54.         include rxdosdef.asm
  55.         include rxdoscin.asm
  56.  
  57.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  58.         ;  RxDOS Command Shell                                          ;
  59.         ;...............................................................;
  60.  
  61. RxDOSCMD SEGMENT PUBLIC 'CODE'
  62.          assume cs:RxDOSCMD, ds:RxDOSCMD, es:RxDOSCMD, ss:RxDOSCMD
  63.  
  64.         public DisplayPrompt
  65.         public formatCurrentDate
  66.         public formatCurrentTime
  67.  
  68.         public _Prompt
  69.         public _Date
  70.         public _Time
  71.  
  72.         extrn CheckOptOneArg                            : near
  73.         extrn _sprintf                                  : near
  74.         extrn DisplayLine                               : near
  75.         extrn _GetNumber                                : near
  76.         extrn _getStdinLine                             : near
  77.         extrn RxDOS_DefaultPrompt                       : near
  78.         extrn RxDOS_Prompt                              : near
  79.         extrn _CopyString                               : near
  80.         extrn RxDOS_PromptSpec                          : near
  81.         extrn searchEnvVariable                         : near
  82.         extrn deleteEnvVariable                         : near
  83.         extrn insertEnvVariable                         : near
  84.         extrn _PleaseEnterDate                          : near
  85.         extrn _ShowCurrentDate                          : near
  86.         extrn _ShowCurrentTime                          : near
  87.         extrn _PleaseEnterTime                          : near
  88.         extrn CmndError_InvalidDate                     : near
  89.         extrn CmndError_InvalidTime                     : near
  90.  
  91.         extrn _lowerCase                                : near
  92.         extrn CRLF                                      : near
  93.         extrn RxDOS_Version                             : near
  94.         extrn RxDOSIntl_DateTemplate                    : near
  95.         extrn RxDOSIntl_DayOfWeek                       : near
  96.         extrn RxDOSIntl_TimeTemplate                    : near
  97.  
  98.         extrn _EnvSegment                               : word
  99.  
  100.  
  101.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  102.         ;  Display Prompt                                               ;
  103.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  104.         ;                                                               ;
  105.         ;  Usage:                                                       ;
  106.         ;   $q     =                                                    ;
  107.         ;   $$     $                                                    ;
  108.         ;   $t     time                                                 ;
  109.         ;   $d     date                                                 ;
  110.         ;   $p     drive:path                                           ;
  111.         ;   $v     current rxdos version                                ;
  112.         ;   $n     drive                                                ;
  113.         ;   $g     >                                                    ;
  114.         ;   $l     <                                                    ;
  115.         ;   $b     | (pipe)                                             ;
  116.         ;   $_     cr lf                                                ;
  117.         ;   $e     esc                                                  ;
  118.         ;   $h     backspace                                            ;
  119.         ;...............................................................;
  120.  
  121. DisplayPrompt:
  122.  
  123.         Entry
  124.         defbytes _buffer, 128
  125.  
  126. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  127. ;  locate init (env) prompt string
  128. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  129.         push di
  130.  
  131.         mov si, offset RxDOS_PromptSpec
  132.         call searchEnvVariable                          ; locate prompt= spec
  133.         jnz DisplayPrompt_06                            ; if none --> 
  134.  
  135.         push ds
  136.         add di, dx                                      ; point to env string
  137.         mov si, offset RxDOS_Prompt
  138.         mov ds, word ptr [ _EnvSegment ]                ; seg of env strings
  139.         xchg di, si
  140.         call _CopyString
  141.         pop ds
  142.  
  143. DisplayPrompt_06:
  144.         mov si, offset RxDOS_Prompt
  145.         lea di, offset [ _buffer ][ bp ]
  146.         mov byte ptr [ di ], 00
  147.  
  148. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  149. ;  scan prompt
  150. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  151. DisplayPrompt_08:
  152.         lodsb
  153.  
  154. DisplayPrompt_10:
  155.         stosb
  156.         or al, al
  157.         ifz DisplayPrompt_48
  158.  
  159.         cmp al, '$'
  160.         jnz DisplayPrompt_08
  161.  
  162. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  163. ;  special case
  164. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  165.         dec di
  166.         lodsb
  167.         or al, al 
  168.         ifz DisplayPrompt_48
  169.  
  170.         call _lowerCase
  171.         Translate 'q', '=', DisplayPrompt_18
  172.         Translate '$', '$', DisplayPrompt_18
  173.         Translate 'g', '>', DisplayPrompt_18
  174.         Translate 'l', '<', DisplayPrompt_18
  175.         Translate 'b', '|', DisplayPrompt_18
  176.         Translate 'e', '['-40h, DisplayPrompt_18
  177.  
  178.         cmp al, 't'                             
  179.         ifz DisplayPrompt_Time                          ; $t time -->
  180.         cmp al, 'd'
  181.         ifz DisplayPrompt_Date                          ; $d date -->
  182.         cmp al, 'p'
  183.         ifz DisplayPrompt_Path                          ; $p path -->
  184.         cmp al, 'v'
  185.         ifz DisplayPrompt_Version                       ; $v version -->
  186.         cmp al, 'n'
  187.         ifz DisplayPrompt_Drive                         ; $d drive -->
  188.         cmp al, '_'
  189.         jz DisplayPrompt_CRLF                           ; $_ crlf -->
  190.         cmp al, 'h'
  191.         jz DisplayPrompt_Backspace                      ; $b backspace -->
  192.         jmp DisplayPrompt_10
  193.  
  194. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  195. ;  translate 
  196. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  197. DisplayPrompt_18:
  198.  
  199.         mov al, ah
  200.         stosb                                           ; translated value
  201.         jmp DisplayPrompt_08
  202.  
  203. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  204. ;  backspace
  205. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  206. DisplayPrompt_Backspace:
  207.         
  208.         dec di
  209.         jmp DisplayPrompt_08
  210.  
  211. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  212. ;  cr lf
  213. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  214. DisplayPrompt_CRLF:
  215.  
  216.         mov ax, 0a0dh
  217.         stosw
  218.         jmp DisplayPrompt_08
  219.  
  220. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  221. ;  time of day
  222. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  223. DisplayPrompt_Time:
  224.  
  225.         call formatCurrentTime
  226.         jmp DisplayPrompt_08
  227.  
  228. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  229. ;  date
  230. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  231. DisplayPrompt_Date:
  232.  
  233.         call formatCurrentDate
  234.         jmp DisplayPrompt_08
  235.  
  236. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  237. ;  path
  238. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  239. DisplayPrompt_Path:
  240.  
  241.         push si
  242.  
  243.         Int21 CurrentDisk 
  244.         mov dl, al                                      ; save drive letter
  245.         add al, 'A'                                     ; get drive
  246.         stosb
  247.  
  248.         mov ax, '\:'
  249.         stosw                                           ; d:\ ...
  250.  
  251.         inc dl
  252.         mov si, di
  253.         mov byte ptr [ si ], 0
  254.         Int21 GetCurrentDirectory                       ; get current directory
  255.  
  256. DisplayPrompt_Path_08:
  257.         lodsb
  258.         or al, al
  259.         jnz DisplayPrompt_Path_08
  260.  
  261.         dec si
  262.         mov di, si
  263.  
  264.         pop si        
  265.         jmp DisplayPrompt_08
  266.         
  267. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  268. ;  version
  269. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  270. DisplayPrompt_Version:
  271.  
  272.         push si
  273.         mov si, offset RxDOS_Version
  274.         call _CopyString
  275.         dec di
  276.         pop si
  277.         jmp DisplayPrompt_08
  278.  
  279. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  280. ;  drive letter
  281. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  282. DisplayPrompt_Drive:
  283.  
  284.         Int21 CurrentDisk
  285.         add al, 'A'                                     ; get drive
  286.         stosb
  287.         jmp DisplayPrompt_08
  288.  
  289. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  290. ;  display prompt
  291. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  292. DisplayPrompt_48:
  293.         lea dx, offset [ _buffer ][ bp ]
  294.         call Displayline
  295.  
  296.         pop di
  297.         Return
  298.  
  299.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  300.         ;  Convert AL To 2 Char Decimal                                 ;
  301.         ;...............................................................;
  302.  
  303. ConvTo2CharDecimal:
  304.  
  305.         push cx
  306.         xor ah, ah
  307.         mov cl, 10
  308.         div cl
  309.         or ax, '00'
  310.         stosw
  311.  
  312.         pop cx
  313.         ret
  314.  
  315.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  316.         ;  Convert AX To 4 Char Decimal                                 ;
  317.         ;...............................................................;
  318.  
  319. ConvTo4CharDecimal:
  320.  
  321.         push cx
  322.         add di, 4
  323.         push di
  324.  
  325. __4CharDecimal_04:
  326.         xor dx, dx
  327.         mov cx, 10
  328.         div cx
  329.  
  330.         dec di
  331.         or dl, '0'
  332.         mov byte ptr [ di ], dl
  333.  
  334.         or ax, ax
  335.         jnz __4CharDecimal_04
  336.  
  337.         pop di
  338.         pop cx
  339.         ret
  340.  
  341.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  342.         ;  Format Date String                                           ;
  343.         ;...............................................................;
  344.  
  345. formatCurrentDate:
  346.         
  347.         Entry
  348.         defbytes _countryInfo, 128
  349.  
  350.         push si
  351.         push di
  352.         mov si, offset RxDOSIntl_DateTemplate
  353.         call _CopyString
  354.  
  355.     ; eventually, make this international
  356.  
  357.         lea dx, offset [ _countryInfo ][ bp ]
  358.         Int21 CountryDependentInfo                      ; get country info
  359.  
  360.         Int21 GetDate
  361.  
  362.         pop di
  363.         xor ah, ah
  364.         mov si, ax
  365.         add si, si
  366.         add si, ax                                      ; offset to day of week text
  367.         add si, offset RxDOSIntl_DayOfWeek
  368.  
  369.         push cx
  370.         mov cx, 3
  371.         rep movsb                                       ; copy 3 bytes
  372.  
  373.         inc di
  374.         mov al, dh                                      ; mon
  375.         call ConvTo2CharDecimal
  376.  
  377.         inc di
  378.         mov al, dl                                      ; day
  379.         call ConvTo2CharDecimal
  380.  
  381.         inc di
  382.         pop ax                                          ; year
  383.         call ConvTo4CharDecimal
  384.  
  385.         pop si
  386.         Return
  387.  
  388.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  389.         ;  Format Time String                                           ;
  390.         ;...............................................................;
  391.  
  392. formatCurrentTime:
  393.  
  394.         Entry
  395.         defbytes _countryInfo, 128
  396.  
  397.         push si
  398.         push di
  399.         mov si, offset RxDOSIntl_TimeTemplate
  400.         call _CopyString
  401.  
  402.     ; eventually, make this international
  403.  
  404.         lea dx, offset [ _countryInfo ][ bp ]
  405.         Int21 CountryDependentInfo                      ; get country info
  406.  
  407.         Int21 GetTime
  408.  
  409.         pop di
  410.         mov al, ch                                      ; hours
  411.         call ConvTo2CharDecimal
  412.  
  413.         inc di
  414.         mov al, cl                                      ; minutes
  415.         call ConvTo2CharDecimal
  416.  
  417.         inc di
  418.         mov al, dh                                      ; seconds
  419.         call ConvTo2CharDecimal
  420.  
  421.         inc di
  422.         mov al, dh                                      ; hundreths
  423.         call ConvTo2CharDecimal
  424.  
  425.         pop si
  426.         Return
  427.  
  428.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  429.         ;  Date [ date ]                                                ;
  430.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  431.         ;                                                               ;
  432.         ;  Usage:                                                       ;
  433.         ;   ss:di  Arg Array                                            ;
  434.         ;   ax     Number of arguments in array                         ;
  435.         ;...............................................................;
  436.  
  437. _Date:
  438.  
  439.         Entry
  440.         def _month
  441.         def _day
  442.         def _year
  443.         def __argarray, di                              ; args array
  444.         defbytes _buffer, 128                           ; input buffer
  445.         defbytes _printbuffer, 128
  446.  
  447.         call CheckOptOneArg                             ; see if 1 arg 
  448.         ifc _dateInvalid                                ; if error in args 
  449.  
  450.         mov si, word ptr [ di ]                         ; get first arg
  451.         or si, si                                       ; if arg, go parse -->
  452.         jnz _date_26
  453.  
  454. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  455. ;  display current date
  456. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  457.  
  458.         lea di, offset [ _buffer ][ bp ]
  459.         push di                                         ; address of 
  460.         call formatCurrentDate                          ; get current date
  461.  
  462.         mov di, offset _ShowCurrentDate
  463.         push di
  464.         lea di, offset [ _printbuffer ][ bp ]
  465.         push di
  466.         call _sprintf
  467.         add sp, ax                                      ; # args passed
  468.         call DisplayLine
  469.  
  470. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  471. ;  please enter date
  472. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  473.  
  474. _date_12:
  475.         mov dx, offset _PleaseEnterDate
  476.         call DisplayLine
  477.  
  478.         lea di, offset [ _buffer ][ bp ]
  479.         mov byte ptr [ bufMaxLength ][ di ], 128
  480.         mov word ptr [ bufActualLength ][ di ], 0
  481.  
  482.         mov dx, di                                      ; where buffer
  483.         call _getStdinLine                              ; read buffer
  484.         
  485.         call CRLF
  486.  
  487.         mov bl, byte ptr [ _buffer. bufActualLength ][ bp ]
  488.         and bx, 255
  489.         ifz _dateReturn
  490.  
  491.         add bx, bp
  492.         mov byte ptr [ _buffer. bufData ][ bx ], 00     ; place a null terminator
  493.         lea si, offset [ _buffer. bufData ][ bp ]       ; parse text
  494.         
  495. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  496. ;  parse arg at [ si ]       ** must internationalize by matching template **
  497. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  498.  
  499. _date_26:
  500.         call _GetNumber                                 ; get month
  501.         mov word ptr [ _month ][ bp ], dx
  502.  
  503.         cmp byte ptr [ si-1 ], '-'
  504.         jz  _date_28                                    ; get day -->
  505.         cmp byte ptr [ si-1 ], '/'        
  506.         jz  _date_28                                    ; get day -->
  507.         cmp byte ptr [ si-1 ], '.'        
  508.         jnz  _dateInvalid                               ; else invalid -->
  509.  
  510. _date_28:
  511.         call _GetNumber                                 ; get day
  512.         mov word ptr [ _day ][ bp ], dx
  513.  
  514.         cmp byte ptr [ si-1 ], '-'
  515.         jz  _date_32                                    ; get year -->
  516.         cmp byte ptr [ si-1 ], '/'        
  517.         jz  _date_32                                    ; get year -->
  518.         cmp byte ptr [ si-1 ], '.'        
  519.         jnz  _dateInvalid                               ; else invalid -->
  520.  
  521. _date_32:
  522.         call _GetNumber                                 ; get year
  523.  
  524.         mov ax, dx
  525.         cmp ax, 1980                                    ; greater than 1980 ?
  526.         jnc _date_42                                    ; valid -->
  527.         cmp ax, 80                                      ; less than 80 ?
  528.         jnc _date_36                                    ; 
  529.         add ax, 2000                                    ; must be between 2000 - 2099
  530.  
  531. _date_36:
  532.         cmp ax, 100                                     ; between 80 and 100 ?
  533.         jnc _date_38                                    ; no -->
  534.         add ax, 1900
  535.  
  536. _date_38:
  537.         cmp ax, 1980
  538.         jc _dateInvalid                                 ; if invalid -->
  539.         cmp ax, 2100
  540.         jnc _dateInvalid                                ; if invalid -->
  541.  
  542. _date_42:
  543.         mov word ptr [ _year ][ bp ], dx
  544.  
  545.         mov cx, ax
  546.         mov dh, byte ptr [ _month ][ bp ]
  547.         mov dl, byte ptr [ _day   ][ bp ]
  548.         Int21 SetDate
  549.         or al, al                                       ; date valid ?
  550.         jnz _dateInvalid                                ; no -->
  551.  
  552. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  553. ;  return
  554. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  555.  
  556. _dateReturn:
  557.         Return
  558.  
  559. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  560. ;  invalid date
  561. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  562.  
  563. _dateInvalid:
  564.         mov dx, offset CmndError_InvalidDate
  565.         call DisplayLine
  566.         jmp _date_12
  567.  
  568.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  569.         ;  Prompt                                                       ;
  570.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  571.         ;                                                               ;
  572.         ;  Usage:                                                       ;
  573.         ;   ss:di  Arg Array                                            ;
  574.         ;   ax     Number of arguments in array                         ;
  575.         ;...............................................................;
  576.  
  577. _Prompt:
  578.  
  579.         mov si, word ptr [ di ]                         ; get pointer to arg
  580.         or si, si
  581.         jnz _prompt_08
  582.         mov si, offset RxDOS_DefaultPrompt
  583.  
  584. _prompt_08:
  585.         mov di, offset RxDOS_Prompt
  586.         call _CopyString
  587.  
  588. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  589. ;  insert prompt=
  590. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  591.  
  592.         mov si, offset RxDOS_PromptSpec                 ; locate PROMPT=
  593.         call searchEnvVariable                          ; env variable located ?
  594.         jnz _prompt_12                                  ; if no arg located -->
  595.         call deleteEnvVariable
  596.  
  597. _prompt_12:
  598.         mov si, offset RxDOS_PromptSpec                 ; insert PROMPT=
  599.         call insertEnvVariable
  600.  
  601.         dec di
  602.         mov si, offset RxDOS_Prompt
  603.         call insertEnvVariable
  604.  
  605.         ret
  606.  
  607.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  608.         ;  Time [ time ]                                                ;
  609.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  610.         ;                                                               ;
  611.         ;  Usage:                                                       ;
  612.         ;   ss:di  Arg Array                                            ;
  613.         ;   ax     Number of arguments in array                         ;
  614.         ;...............................................................;
  615.  
  616. _Time:
  617.  
  618.         Entry
  619.         def _hours
  620.         def _minutes
  621.         def _seconds
  622.         def _hundredths
  623.  
  624.         def __argarray, di                              ; args array
  625.         defbytes _buffer, 128                           ; input buffer
  626.         defbytes _printbuffer, 128
  627.  
  628.         call CheckOptOneArg                             ; see if 1 arg 
  629.         ifc _timeInvalid                                ; if error in args 
  630.  
  631.         mov si, word ptr [ di ]                         ; get first arg
  632.         or si, si                                       ; if arg, go parse -->
  633.         jnz _time_26
  634.  
  635. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  636. ;  display current time
  637. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  638.  
  639.         lea di, offset [ _buffer ][ bp ]
  640.         push di
  641.         call formatCurrentTime                          ; get current time
  642.  
  643.         mov di, offset _ShowCurrentTime
  644.         push di
  645.         lea di, offset [ _printbuffer ][ bp ]
  646.         push di
  647.         call _sprintf
  648.         add sp, ax                                      ; # args passed
  649.         call DisplayLine
  650.  
  651. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  652. ;  please enter time
  653. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  654.  
  655. _time_12:
  656.         mov dx, offset _PleaseEnterTime
  657.         call DisplayLine
  658.  
  659.         lea di, offset [ _buffer ][ bp ]
  660.         mov byte ptr [ bufMaxLength ][ di ], 128
  661.         mov word ptr [ bufActualLength ][ di ], 0
  662.  
  663.         mov dx, di                                      ; where buffer
  664.         call _getStdinLine                              ; read buffer
  665.         
  666.         call CRLF
  667.  
  668.         mov bl, byte ptr [ _buffer. bufActualLength ][ bp ]
  669.         and bx, 255
  670.         ifz _timeReturn
  671.  
  672.         add bx, bp
  673.         mov byte ptr [ _buffer. bufData ][ bx ], 00     ; place a null terminator
  674.         lea si, offset [ _buffer. bufData ][ bp ]       ; parse text
  675.         
  676. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  677. ;  parse arg at [ si ]       ** must internationalize by matching template **
  678. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  679.  
  680. _time_26:
  681.         xor ax, ax
  682.         storarg _hours, ax
  683.         storarg _minutes, ax
  684.         storarg _seconds, ax
  685.         storarg _hundredths, ax
  686.  
  687.         call _GetNumber                                 ; get hours
  688.         mov word ptr [ _hours ][ bp ], dx
  689.  
  690.         call _checkSeparator
  691.         jc _timeInvalid
  692.         jz _time_36
  693.         call _GetNumber                                 ; get mins
  694.         mov word ptr [ _minutes ][ bp ], dx
  695.  
  696.         call _checkSeparator
  697.         jc _timeInvalid
  698.         jz _time_36
  699.         call _GetNumber                                 ; get seconds
  700.         mov word ptr [ _seconds ][ bp ], dx
  701.  
  702.         call _checkSeparator
  703.         jc _timeInvalid
  704.         jz _time_36
  705.         call _GetNumber                                 ; get hundreths of seconds
  706.         mov word ptr [ _hundredths ][ bp ], dx
  707.  
  708. _time_36:
  709.         mov dl, byte ptr [ _hundredths ][ bp ]
  710.         mov dh, byte ptr [ _seconds    ][ bp ]
  711.         mov ch, byte ptr [ _hours      ][ bp ]
  712.         mov cl, byte ptr [ _minutes    ][ bp ]
  713.         Int21 SetTime
  714.         or al, al                                       ; date valid ?
  715.         jnz _timeInvalid                                ; no -->
  716.  
  717. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  718. ;  return
  719. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  720.  
  721. _timeReturn:
  722.         Return
  723.  
  724. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  725. ;  invalid time
  726. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  727.  
  728. _timeInvalid:
  729.         mov dx, offset CmndError_InvalidTime
  730.         call DisplayLine
  731.         jmp _time_12
  732.  
  733.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  734.         ;  Test Time Separator                                          ;
  735.         ;...............................................................;
  736.  
  737. _checkSeparator:
  738.  
  739.         mov al, byte ptr [ si-1 ]                       ; get last character processed
  740.         or al, al                                       ; if end of line -->
  741.         jz _checkSeparator_24                           ; return end of line -->
  742.  
  743.         cmp al, ' '
  744.         jnz _checkSeparator_06                          ; skip any spaces -->
  745.  
  746.         inc si
  747.         jmp _checkSeparator
  748.  
  749. _checkSeparator_06:
  750.         call _lowerCase
  751.  
  752.         cmp al, ':'
  753.         jz _checkSeparator_24                           ; return end of line -->
  754.         cmp al, '.'        
  755.         jz _checkSeparator_24                           ; return end of line -->
  756.  
  757.         cmp al, 'a'                                     ; am / pm ?
  758.         jz _checkSeparator_12                           ; yes -->
  759.         cmp al, 'p'                                     ; am / pm ?
  760.         jz _checkSeparator_10                           ; yes -->
  761.  
  762.         stc                                             ; anything else is an error
  763.         ret
  764.  
  765. _checkSeparator_10:
  766.         cmp byte ptr [ _hours ][ bp ], 12
  767.         jge _checkSeparator_12
  768.         add byte ptr [ _hours ][ bp ], 12
  769.  
  770. _checkSeparator_12:
  771.         xor ax, ax
  772.  
  773. _checkSeparator_24:
  774.         or al, al
  775.         ret
  776.  
  777. RxDOSCMD                        ENDS
  778.                                 END
  779.  
  780.